<template>
    <div>
        <div class="sky">
            <div class="sky__phase sky__dawn"></div>
            <div class="sky__phase sky__noon"></div>
            <div class="sky__phase sky__dusk"></div>
            <div class="sky__phase sky__midnight">
                <div id="sky__stars">
                    <div style="left: 46%; top: 55%;"></div>
                    <div style="left: 21%; top: 40%;"></div>
                    <div style="left: 53%; top: 53%;"></div>
                    <div style="left: 65%; top: 58%;"></div>
                    <div style="left: 49%; top: 43%;"></div>
                    <div style="left: 53%; top: 15%;"></div>
                    <div style="left: 33%; top: 24%;"></div>
                    <div style="left: 99%; top: 89%;"></div>
                    <div style="left: 52%; top: 83%;"></div>
                    <div style="left: 6%; top: 73%;"></div>
                    <div style="left: 8%; top: 71%;"></div>
                    <div style="left: 96%; top: 58%;"></div>
                    <div style="left: 47%; top: 36%;"></div>
                    <div style="left: 40%; top: 21%;"></div>
                    <div style="left: 40%; top: 30%;"></div>
                    <div style="left: 86%; top: 7%;"></div>
                    <div style="left: 38%; top: 12%;"></div>
                    <div style="left: 11%; top: 1%;"></div>
                    <div style="left: 33%; top: 56%;"></div>
                    <div style="left: 83%; top: 12%;"></div>
                    <div style="left: 63%; top: 64%;"></div>
                    <div style="left: 53%; top: 84%;"></div>
                    <div style="left: 50%; top: 2%;"></div>
                    <div style="left: 77%; top: 52%;"></div>
                    <div style="left: 82%; top: 23%;"></div>
                    <div style="left: 29%; top: 20%;"></div>
                    <div style="left: 56%; top: 56%;"></div>
                    <div style="left: 69%; top: 94%;"></div>
                    <div style="left: 15%; top: 57%;"></div>
                    <div style="left: 33%; top: 35%;"></div>
                    <div style="left: 33%; top: 94%;"></div>
                    <div style="left: 57%; top: 13%;"></div>
                    <div style="left: 4%; top: 60%;"></div>
                    <div style="left: 18%; top: 84%;"></div>
                    <div style="left: 68%; top: 55%;"></div>
                    <div style="left: 75%; top: 11%;"></div>
                    <div style="left: 73%; top: 64%;"></div>
                    <div style="left: 72%; top: 81%;"></div>
                    <div style="left: 91%; top: 96%;"></div>
                    <div style="left: 35%; top: 67%;"></div>
                </div>
            </div>
            <div class="orbit">
                <div class="sun"></div>
                <div class="moon"></div>
            </div>
        </div>
        <el-row :gutter="20">
            <br><br><br><br>
            <el-col :span="18" :offset="3">
                <el-card shadow="always">
                    <el-row :gutter="20">
                        <el-col :span="4" :offset="10" style="margin-left:50%;">
                            <i class="el-icon-user-solid" />
                        </el-col>
                    </el-row>
                    <br><br><br>
                    <el-form :model="numberValidateForm" ref="numberValidateForm" label-width="100px"
                        class="demo-ruleForm">
                        <el-row :gutter="20">
                            <el-col :span="12" :offset="6">
                                <el-form-item label="账号昵称" prop="account" :rules="[
                                    { required: true, message: '账号不能为空' },
                                ]">
                                    <el-input placeholder="请输入账号" v-model="numberValidateForm.account" clearable />
                                </el-form-item>
                            </el-col>
                            <el-col :span="12" :offset="6">
                                <el-form-item label="密码" prop="password" :rules="[
                                    { required: true, message: '密码不能为空' },
                                ]">
                                    <el-input placeholder="请输入密码" v-model="numberValidateForm.password" show-password />
                                </el-form-item>
                            </el-col>
                            <el-col :span="12" :offset="6">
                                <el-form-item label="验证码" prop="validCode">
                                    <div style="display: flex">
                                        <el-input prefix-icon="el-icon-key" v-model="numberValidateForm.validCode"
                                            style="width: 50%;" placeholder="请输入验证码"></el-input>
                                        <ValidCode @input="createValidCode"></ValidCode>
                                    </div>
                                </el-form-item>
                            </el-col>
                            <el-col :span="4" :offset="10" style="margin-left:40%">
                                <el-form-item>
                                    <el-button type="primary" @click="submitForm('numberValidateForm')">提交</el-button>
                                </el-form-item>
                            </el-col>
                        </el-row>

                        <el-row :gutter="20">
                            <el-col :span="6" :offset="6">
                                <router-link to="/enroll">点击这里注册</router-link>
                            </el-col>
                        </el-row>
                    </el-form>
                </el-card>
            </el-col>
        </el-row>
    </div>
</template>
<script>
import { login } from '@/utils/requests'
import ValidCode from "@/component/ValidCode.vue"
import qs from 'qs'
export default {
    components: {
        ValidCode
    },
    data() {
        return {
            numberValidateForm: {
                account: '',
                password: '',
                validCode: ''
            },
            validCode: ''
        }
    },
    methods: {
        // 接收验证码组件提交的 4位验证码
        createValidCode(data) {
            this.validCode = data
        },
        submitForm(formName) {
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    if (!this.numberValidateForm.validCode) {
                        this.$message.error("请填写验证码")
                        return
                    }
                    if (this.numberValidateForm.validCode.toLowerCase() !== this.validCode.toLowerCase()) {
                        this.$message.error("验证码错误")
                        return
                    }
                    login(qs.stringify(this.numberValidateForm)).then((res) => {
                        let accessToken = res.data.token
                        window.sessionStorage.setItem('accessToken', accessToken)
                        // if(res.data.)
                        console.log(res.data)
                        if (res.data.employee) {
                            if (res.data.employee.account == 'admin') {
                                this.$router.push({
                                    path: '/',
                                })
                            } else {
                                this.$router.push({
                                    path: '/employee'
                                })
                            }
                        } else {
                            this.$router.push({
                                path: '/customer'
                            })
                        }

                    }).catch(err => {
                        this.$message({
                            type: 'error',
                            message: err.message,
                            showClose: true
                        })
                    })

                } else {
                    console.log('error submit!!');
                    return false;
                }
            });
        },

    }
}
</script>
<style>
.el-icon-user-solid:before {
    font-size: 70px;
}

/*装修公司 : 1找标签 2 对标签 样式的 装修  */
body {
    margin: 0;
    background-size: cover;
}

h2 {
    margin: 0;
}

input {
    border: none;
    outline: none;
    background: transparent;
}

.login {
    width: 400px;
    /* 宽度: 400像素;长度单位 */
    /* height: 300px; */
    /* 高度 */
    /* margin: 100px; */
    /* 外边距 */
    margin: 100px auto;
    padding: 30px;
    background-color: rgba(0, 0, 0, .8);
    /* 背景颜色 */
    /* opacity: .6; */
    border-radius: 10px;
}

.login h2 {
    color: #fff;
    /* 文字变白 */
    text-align: center;
    /* 文本水平居中 */
    margin-bottom: 30px;
    /* 下外边距 */
}

.inputbox {
    position: relative;
    /* 相对定位 */
    margin: 20px 0;
}

.inputbox input {
    width: 100%;
    border-bottom: 1px solid #fff;
    color: #fff;
}

.inputbox label {
    position: absolute;
    /* 定位 */
    /* top上 bottom下 left左 right右 */
    top: 0;
    left: 0;
    color: red;
    transition: all 0.6s;
    pointer-events: none;
    /* 看的见摸不着 */
}

.inputbox input:focus~label,
.inputbox input:valid~label {
    top: -18px;
    left: 0;
    color: #03a9f4;
    font-size: 12px;
}

input[type="submit"] {
    color: #fff;
    background: #03a9f4;
    padding: 10px 20px;
    border-radius: 5px;
}

#item {
    width: 200px;
    height: 50px;
}

#input {
    width: 100px
}

@-webkit-keyframes sunrise {
    from {
        transform: rotate(-45deg);
    }

    to {
        transform: rotate(315deg);
    }
}

@keyframes sunrise {
    from {
        transform: rotate(-45deg);
    }

    to {
        transform: rotate(315deg);
    }
}

@-webkit-keyframes moonrise {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(180deg);
    }
}

@keyframes moonrise {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(180deg);
    }
}

@-webkit-keyframes dawn {
    0% {
        opacity: 0;
    }

    10% {
        opacity: 1;
    }

    60% {
        opacity: 0;
    }
}

@keyframes dawn {
    0% {
        opacity: 0;
    }

    10% {
        opacity: 1;
    }

    60% {
        opacity: 0;
    }
}

@-webkit-keyframes noon {
    0% {
        opacity: 0;
    }

    50% {
        opacity: 1;
    }

    75% {
        opacity: 0;
    }
}

@keyframes noon {
    0% {
        opacity: 0;
    }

    50% {
        opacity: 1;
    }

    75% {
        opacity: 0;
    }
}

@-webkit-keyframes dusk {
    0% {
        opacity: 0;
    }

    50% {
        opacity: 0;
    }

    70% {
        opacity: 1;
    }

    90% {
        opacity: 0;
    }
}

@keyframes dusk {
    0% {
        opacity: 0;
    }

    50% {
        opacity: 0;
    }

    70% {
        opacity: 1;
    }

    90% {
        opacity: 0;
    }
}

@-webkit-keyframes midnight {
    0% {
        opacity: 1;
    }

    25% {
        opacity: 0;
    }

    50% {
        opacity: 0;
    }

    80% {
        opacity: 1;
    }
}

@keyframes midnight {
    0% {
        opacity: 1;
    }

    25% {
        opacity: 0;
    }

    50% {
        opacity: 0;
    }

    80% {
        opacity: 1;
    }
}

body {
    --animation-speed: 24s;
    background-color: rgb(37, 29, 24);
}

.sky {
    width: 100vw;
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    /* max-height: 600px; */
    overflow: hidden;
}

.sky__phase {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 100%;
    transition: opacity 0.2s;
}

.sky__dawn {
    background: linear-gradient(0deg,
            rgba(254, 215, 102, 1) 0%,
            rgba(205, 237, 246, 1) 100%);
    -webkit-animation: linear dawn infinite var(--animation-speed);
    animation: linear dawn infinite var(--animation-speed);
}

.sky__noon {
    background: linear-gradient(0deg,
            rgba(205, 237, 246, 1) 0%,
            rgba(36, 123, 160, 1) 100%);
    -webkit-animation: linear noon infinite var(--animation-speed);
    animation: linear noon infinite var(--animation-speed);
}

.sky__dusk {
    background: linear-gradient(0deg,
            rgba(255, 32, 110, 1) 0%,
            rgba(10, 0, 94, 1) 100%);
    -webkit-animation: linear dusk infinite var(--animation-speed);
    animation: linear dusk infinite var(--animation-speed);
}

.sky__midnight {
    background: linear-gradient(0deg,
            rgba(2, 0, 20, 1) 0%,
            rgba(10, 0, 94, 1) 100%);
    -webkit-animation: linear midnight infinite var(--animation-speed);
    animation: linear midnight infinite var(--animation-speed);
}

.orbit {
    position: relative;
    width: 500px;
    height: 500px;
    margin: 200px auto;
    transform: rotate(-45deg);
    -webkit-animation: linear sunrise infinite var(--animation-speed);
    animation: linear sunrise infinite var(--animation-speed);
}

@media (min-width: 768px) {
    .sky {
        min-height: 600px;
    }

    .orbit {
        width: 700px;
        height: 700px;
        margin: 150px auto;
    }
}

@media (min-width: 940px) {
    .orbit {
        width: 800px;
        height: 800px;
    }
}

@media (min-width: 1200px) {
    body {
        --animation-speed: 28s;
    }

    .orbit {
        width: 1000px;
        height: 1000px;
        margin: 200px auto;
    }
}

@media (min-width: 1500px) {
    body {
        --animation-speed: 30s;
    }

    .orbit {
        width: 1300px;
        height: 1300px;
    }
}

.sun {
    position: absolute;
    top: -40px;
    left: -40px;
    width: 80px;
    height: 80px;
    background-color: rgb(254, 215, 102);
    border-radius: 50%;
    box-shadow: 0 0 14px 14px rgba(254, 215, 102, 0.2);
}

.moon {
    position: absolute;
    bottom: -40px;
    right: -40px;
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background-color: #fff;
    box-shadow: 0 0 7px 7px rgba(255, 255, 255, 0.2);
}

#sky__stars>div {
    width: 3px;
    height: 3px;
    background-color: #fff;
    border-radius: 50%;
    position: absolute;
}
</style>